﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PublicData;
using System.Linq;
using XinjeMesProgram.Entities;
using XinjeMesProgram.Entities.BookInfo;

namespace MesAPI.Controllers.Book
{
    /// <summary>
    /// book.
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class BookController : ControllerBase
    {
        private readonly ResponseModel response = new ResponseModel();

        /// <summary>
        /// 0.
        /// </summary>
        /// <param name="current">1.</param>
        /// <param name="pageSize">2.</param>
        /// <param name="BookingListNo">3.</param>
        /// <param name="BookingSendTime">4.</param>
        /// <param name="BookingStatues">5.</param>
        /// <returns>返回.</returns>
        [HttpGet]
        public ResponseModel Getallinfo(int current, int pageSize, string? BookingListNo, string? BookingSendTime, string? BookingStatues)
        {
            List<BookingListInfoModel> bookings;
            if (XinjeMesProgram.XinjeMesProgram.MesSer.BookingListInfos.Count != 0)
            {
                bookings = XinjeMesProgram.XinjeMesProgram.MesSer.BookingListInfos;
                if (!string.IsNullOrEmpty(BookingListNo))
                {
                    bookings = XinjeMesProgram.XinjeMesProgram.MesSer.BookingListInfos.Where(x => x.BookingListNo == BookingListNo).ToList();

                }
                if (!string.IsNullOrEmpty(BookingSendTime))
                {
                    bookings = XinjeMesProgram.XinjeMesProgram.MesSer.BookingListInfos.Where(x => x.BookingSendTime >= DateTime.Parse(BookingSendTime)).ToList();
                }
                if (!string.IsNullOrEmpty(BookingStatues))
                {
                    bookings = XinjeMesProgram.XinjeMesProgram.MesSer.BookingListInfos.Where(x => x.BookingStatues == BookingStatues).ToList();
                }
                int count = bookings.Count;
                bookings = bookings.ListPaged(current, pageSize).ToList();
                this.response.SetData(bookings, count);

            }
            else
            {
                bookings = new List<BookingListInfoModel>();
                this.response.SetData(bookings);
            }

            return this.response;
        }
    }
}
